package com.ruoyi.message.feign;

import com.ruoyi.common.core.constant.WebsocketConstants;
import com.ruoyi.message.api.RemoteMessageClient;
import com.ruoyi.message.utils.WeChatService;
import com.ruoyi.message.utils.WebSocketService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/message/client")
public class MessageClient implements RemoteMessageClient {

    private final WebSocketService webSocketService;
    private final WeChatService weChatService;

    /**
     * 发送websocket通知公告消息（给所有客户端）
     * @return
     */
    @PostMapping(value = "/sendWsToAll-notice")
    @Override
    public void sendWsToAllNotice() {
        webSocketService.sendMessage(WebsocketConstants.SUBSCRIBE_SUF_NOTICE, WebsocketConstants.MSG_TYPE_REFRESH_NOTICE);
    }

    /**
     * 发送websocket业务相关消息（给指定客户端）
     * @param userName
     * @return
     */
    @PostMapping(value = "/sendWsToOne-business")
    @Override
    public void sendWsToOneBusiness(@RequestParam("userName") String userName) {
        webSocketService.sendMessage(WebsocketConstants.SUBSCRIBE_SUF_BUSINESS, userName, WebsocketConstants.MSG_TYPE_REFRESH_BUSINESS);
    }

    /**
     * 通过企业微信通知
     * @param msg
     * @return
     */
    @PostMapping(value = "/sendWeChatMessage")
    @Override
    public void sendWeChatMessage(@RequestParam("msg") String msg) {
        weChatService.sendWeChatMsg(msg);
    }

}
